home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / misc / gs261src.zip / scftab.c < prev    next >
C/C++ Source or Header  |  1993-05-13  |  7KB  |  181 lines

  1. /* Copyright (C) 1992 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* scftab.c */
  20. /* Tables for CCITTFax filters (other than run decoding) */
  21. #include "std.h"
  22. #include "scf.h"
  23.  
  24. /* We make this a separate file so that it can be used by */
  25. /* the program that generates the tables for the CCITTFaxDecode filter. */
  26.  
  27. /* ------ Scanning tables ------ */
  28.  
  29. /* Look up the mask that includes the n trailing bits of a byte. */
  30. const byte cf_left_bits[8] =
  31. {    0xff, 1, 3, 7, 0xf, 0x1f, 0x3f, 0x7f
  32. };
  33.  
  34. /* Look up the 1-origin bit index of the leading 1-bit in a byte. */
  35. const byte cf_top_bit[256] =
  36. {    0, 1, 2, 2, 3, 3, 3, 3,   4, 4, 4, 4, 4, 4, 4, 4,
  37.     5, 5, 5, 5, 5, 5, 5, 5,   5, 5, 5, 5, 5, 5, 5, 5,
  38.     6, 6, 6, 6, 6, 6, 6, 6,   6, 6, 6, 6, 6, 6, 6, 6,
  39.     6, 6, 6, 6, 6, 6, 6, 6,   6, 6, 6, 6, 6, 6, 6, 6,
  40.     7, 7, 7, 7, 7, 7, 7, 7,   7, 7, 7, 7, 7, 7, 7, 7,
  41.     7, 7, 7, 7, 7, 7, 7, 7,   7, 7, 7, 7, 7, 7, 7, 7,
  42.     7, 7, 7, 7, 7, 7, 7, 7,   7, 7, 7, 7, 7, 7, 7, 7,
  43.     7, 7, 7, 7, 7, 7, 7, 7,   7, 7, 7, 7, 7, 7, 7, 7,
  44.     8, 8, 8, 8, 8, 8, 8, 8,   8, 8, 8, 8, 8, 8, 8, 8,
  45.     8, 8, 8, 8, 8, 8, 8, 8,   8, 8, 8, 8, 8, 8, 8, 8,
  46.     8, 8, 8, 8, 8, 8, 8, 8,   8, 8, 8, 8, 8, 8, 8, 8,
  47.     8, 8, 8, 8, 8, 8, 8, 8,   8, 8, 8, 8, 8, 8, 8, 8,
  48.     8, 8, 8, 8, 8, 8, 8, 8,   8, 8, 8, 8, 8, 8, 8, 8,
  49.     8, 8, 8, 8, 8, 8, 8, 8,   8, 8, 8, 8, 8, 8, 8, 8,
  50.     8, 8, 8, 8, 8, 8, 8, 8,   8, 8, 8, 8, 8, 8, 8, 8,
  51.     8, 8, 8, 8, 8, 8, 8, 8,   8, 8, 8, 8, 8, 8, 8, 8
  52. };
  53.  
  54. /* ------ Run encoding tables ------ */
  55.  
  56. /* Abbreviate cfe_entry to make the file smaller. */
  57. #define e_(c,len) cfe_entry(c,len)
  58.  
  59. /* Define the end-of-line code. */
  60. /* Code in scfd.c and scfdgen.c knows that the run value is 1. */
  61. const cfe_run cf_run_eol = e_(run_eol_code_value, run_eol_code_length);
  62.  
  63. /* Define the 1-D code that signals uncompressed data. */
  64. const cfe_run cf1_run_uncompressed = e_(0xf, 12);
  65.  
  66. /* Define the 2-D run codes. */
  67. const cfe_run cf2_run_pass = e_(0x1, 4);
  68. const cfe_run cf2_run_vertical[7] = {
  69.     e_(0x3, 7),
  70.     e_(0x3, 6),
  71.     e_(0x3, 3),
  72.     e_(0x1, 1),
  73.     e_(0x2, 3),
  74.     e_(0x2, 6),
  75.     e_(0x2, 7)
  76. };
  77. const cfe_run cf2_run_horizontal = e_(0x1, 3);
  78. const cfe_run cf2_run_uncompressed = e_(0xf, 10);
  79.  
  80. /* EOL codes for Group 3 2-D. */
  81. /* Code in scfd.c knows that these are 0...01x. */
  82. const cfe_run cf2_run_eol_1d =
  83.     e_((run_eol_code_value << 1) + 1, run_eol_code_length + 1);
  84. const cfe_run cf2_run_eol_2d =
  85.     e_((run_eol_code_value << 1) + 0, run_eol_code_length + 1);
  86.  
  87. /* White run termination codes. */
  88. const cfe_run cf_white_termination[64] = {
  89.     e_(0x35, 8), e_(0x7, 6),  e_(0x7, 4),  e_(0x8, 4),
  90.     e_(0xb, 4),  e_(0xc, 4),  e_(0xe, 4),  e_(0xf, 4),
  91.     e_(0x13, 5), e_(0x14, 5), e_(0x7, 5),  e_(0x8, 5),
  92.     e_(0x8, 6),  e_(0x3, 6),  e_(0x34, 6), e_(0x35, 6),
  93.     e_(0x2a, 6), e_(0x2b, 6), e_(0x27, 7), e_(0xc, 7),
  94.     e_(0x8, 7),  e_(0x17, 7), e_(0x3, 7),  e_(0x4, 7),
  95.     e_(0x28, 7), e_(0x2b, 7), e_(0x13, 7), e_(0x24, 7),
  96.     e_(0x18, 7), e_(0x2, 8),  e_(0x3, 8),  e_(0x1a, 8),
  97.     e_(0x1b, 8), e_(0x12, 8), e_(0x13, 8), e_(0x14, 8),
  98.     e_(0x15, 8), e_(0x16, 8), e_(0x17, 8), e_(0x28, 8),
  99.     e_(0x29, 8), e_(0x2a, 8), e_(0x2b, 8), e_(0x2c, 8),
  100.     e_(0x2d, 8), e_(0x4, 8),  e_(0x5, 8),  e_(0xa, 8),
  101.     e_(0xb, 8),  e_(0x52, 8), e_(0x53, 8), e_(0x54, 8),
  102.     e_(0x55, 8), e_(0x24, 8), e_(0x25, 8), e_(0x58, 8),
  103.     e_(0x59, 8), e_(0x5a, 8), e_(0x5b, 8), e_(0x4a, 8),
  104.     e_(0x4b, 8), e_(0x32, 8), e_(0x33, 8), e_(0x34, 8)
  105. };
  106.  
  107. /* White run make-up codes. */
  108. const cfe_run cf_white_make_up[41] = {
  109.     e_(0, 0) /* dummy */, e_(0x1b, 5), e_(0x12, 5), e_(0x17, 6),
  110.     e_(0x37, 7), e_(0x36, 8), e_(0x37, 8), e_(0x64, 8),
  111.     e_(0x65, 8), e_(0x68, 8), e_(0x67, 8), e_(0xcc, 9),
  112.     e_(0xcd, 9), e_(0xd2, 9), e_(0xd3, 9), e_(0xd4, 9),
  113.     e_(0xd5, 9), e_(0xd6, 9), e_(0xd7, 9), e_(0xd8, 9),
  114.     e_(0xd9, 9), e_(0xda, 9), e_(0xdb, 9), e_(0x98, 9),
  115.     e_(0x99, 9), e_(0x9a, 9), e_(0x18, 6), e_(0x9b, 9),
  116.     e_(0x8, 11), e_(0xc, 11), e_(0xd, 11), e_(0x12, 12),
  117.     e_(0x13, 12), e_(0x14, 12), e_(0x15, 12), e_(0x16, 12),
  118.     e_(0x17, 12), e_(0x1c, 12), e_(0x1d, 12), e_(0x1e, 12),
  119.     e_(0x1f, 12)
  120. };
  121.  
  122. /* Black run termination codes. */
  123. const cfe_run cf_black_termination[64] = {
  124.     e_(0x37, 10), e_(0x2, 3),   e_(0x3, 2),   e_(0x2, 2),
  125.     e_(0x3, 3),   e_(0x3, 4),   e_(0x2, 4),   e_(0x3, 5),
  126.     e_(0x5, 6),   e_(0x4, 6),   e_(0x4, 7),   e_(0x5, 7),
  127.     e_(0x7, 7),   e_(0x4, 8),   e_(0x7, 8),   e_(0x18, 9),
  128.     e_(0x17, 10), e_(0x18, 10), e_(0x8, 10),  e_(0x67, 11),
  129.     e_(0x68, 11), e_(0x6c, 11), e_(0x37, 11), e_(0x28, 11),
  130.     e_(0x17, 11), e_(0x18, 11), e_(0xca, 12), e_(0xcb, 12),
  131.     e_(0xcc, 12), e_(0xcd, 12), e_(0x68, 12), e_(0x69, 12),
  132.     e_(0x6a, 12), e_(0x6b, 12), e_(0xd2, 12), e_(0xd3, 12),
  133.     e_(0xd4, 12), e_(0xd5, 12), e_(0xd6, 12), e_(0xd7, 12),
  134.     e_(0x6c, 12), e_(0x6d, 12), e_(0xda, 12), e_(0xdb, 12),
  135.     e_(0x54, 12), e_(0x55, 12), e_(0x56, 12), e_(0x57, 12),
  136.     e_(0x64, 12), e_(0x65, 12), e_(0x52, 12), e_(0x53, 12),
  137.     e_(0x24, 12), e_(0x37, 12), e_(0x38, 12), e_(0x27, 12),
  138.     e_(0x28, 12), e_(0x58, 12), e_(0x59, 12), e_(0x2b, 12),
  139.     e_(0x2c, 12), e_(0x5a, 12), e_(0x66, 12), e_(0x67, 12)
  140. };
  141.  
  142. /* Black run make-up codes. */
  143. const cfe_run cf_black_make_up[41] = {
  144.     e_(0, 0) /* dummy */, e_(0xf, 10), e_(0xc8, 12), e_(0xc9, 12),
  145.     e_(0x5b, 12), e_(0x33, 12), e_(0x34, 12), e_(0x35, 12),
  146.     e_(0x6c, 13), e_(0x6d, 13), e_(0x4a, 13), e_(0x4b, 13),
  147.     e_(0x4c, 13), e_(0x4d, 13), e_(0x72, 13), e_(0x73, 13),
  148.     e_(0x74, 13), e_(0x75, 13), e_(0x76, 13), e_(0x77, 13),
  149.     e_(0x52, 13), e_(0x53, 13), e_(0x54, 13), e_(0x55, 13),
  150.     e_(0x5a, 13), e_(0x5b, 13), e_(0x64, 13), e_(0x65, 13),
  151.     e_(0x8, 11), e_(0xc, 11), e_(0xd, 11), e_(0x12, 12),
  152.     e_(0x13, 12), e_(0x14, 12), e_(0x15, 12), e_(0x16, 12),
  153.     e_(0x17, 12), e_(0x1c, 12), e_(0x1d, 12), e_(0x1e, 12),
  154.     e_(0x1f, 12)
  155. };
  156.  
  157. /* Uncompressed codes. */
  158. const cfe_run cf_uncompressed[6] = {
  159.     e_(1, 1),
  160.     e_(1, 2),
  161.     e_(1, 3),
  162.     e_(1, 4),
  163.     e_(1, 5),
  164.     e_(1, 6)
  165. };
  166.  
  167. /* Uncompressed exit codes. */
  168. const cfe_run cf_uncompressed_exit[10] = {
  169.     e_(2, 8), e_(3, 8),
  170.     e_(2, 9), e_(3, 9),
  171.     e_(2, 10), e_(3, 10),
  172.     e_(2, 11), e_(3, 11),
  173.     e_(2, 12), e_(3, 12)
  174. };
  175.  
  176. /* Some C compilers insist on having executable code in every file.... */
  177. void
  178. cfe_dummy(void)
  179. {
  180. }
  181.